package com.cyzy.service.impl;

import com.cyzy.mapper.FriendsMapper;
import com.cyzy.pojo.TrainFriends;
import com.cyzy.service.FriendsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class FriendsServiceImpl implements FriendsService {

    @Autowired
    private FriendsMapper FriendsMapper;

    //查询乘车人列表
    @Override
    public List<TrainFriends> getFriendList(String userId) {
        List<TrainFriends> friendsList = FriendsMapper.getFriendList(userId);
        return friendsList;
    }

    //根据亲友名字查询
    @Override
    public List<TrainFriends> selectByName(String friendName) {
        List<TrainFriends> friends = FriendsMapper.selectByName(friendName);
        return friends;
    }

    //根据ID查询亲友信息
    @Override
    public TrainFriends selectById(String friendId) {
        TrainFriends friends = FriendsMapper.selectById(friendId);
        return friends;
    }

    //添加乘车人信息
    @Override
    public int addFriends(TrainFriends trainFriends) {
        if(FriendsMapper.selectFriendByPapers(trainFriends.getFriendPapers()) == null){
            trainFriends.setPapersType("居民身份证");
            trainFriends.setFrientsNote("已核验");
            trainFriends.setFriendStatus("0");
            int i = FriendsMapper.addFriends(trainFriends);
            return i;
        }
        return 0;
    }

    //删除乘车人信息
    @Override
    public int deleteFriends(TrainFriends trainFriends) {
        int i = FriendsMapper.deleteFriends(trainFriends.getFriendId());
        return i;
    }

    //批量删除亲友
    @Override
    public int deletes(Long[] friendIds) {
        int deletes = FriendsMapper.deletes(friendIds);
        return deletes;
    }

    //修改亲友信息
    @Override
    public int updateFriends(TrainFriends trainFriends) {
        int i = FriendsMapper.updateFriends(trainFriends);
        return i;
    }
}
